 var id = getvl("id");
 var currentPage=1;
 $(function(){
 	   if(id!=null){
 	   	  selectGoodsList2();
 	   	$("#qaunbu").attr("href","12.8.0buy_dingdan.html?id="+id);
 	   $("#daifahuo").attr("href","12.8.0buy_dingdan_daifahuo.html?id="+id);
 	   $("#daifukuan").attr("href","12.8.0buy_dingdan_daifukuan.html?id="+id);
 	   $("#daishouhuo").attr("href","12.8.0buy_dingdan_daishouhuo.html?id="+id);
 	   $("#daipingjia").attr("href","12.8.0buy_dingdan_daipingjia.html?id="+id);
 	   }else{
 	   	alert("登录异常...");
 	   }
 });
var s=0;
function  selectGoodsList2(){ 
	  if(currentPage==1 || s!=0){
		$.ajax({
             url: urlcore + "/api/order/WXselect?current="+currentPage+"&userId="+id+"&types=1",
            type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					s=data.data.length;
					$.each(data.data,function(y,n) {
						if(n.goodsCarList!=null){
						//alert(n.id);
						  var zhuantai="";
						    if(n.status==0){
						    	zhuantai="未付款";
						    }else if(n.status==1){
						    	if(n.tradeStatus==0){
						    		zhuantai="待发货";
						    	}else if(n.tradeStatus==1){
						    		zhuantai="待收货";
						    	}
						    }else if(n.status==8){
						    	zhuantai="申请退款中";
						    }else if(n.status==9){
						    	zhuantai="退款失败";
						    }else if(n.status==10){
						    	zhuantai="退款成功";
						    }else if(n.tradeStatus==2){
						    	   if(n.status==3){
						    	   	zhuantai="已评价";
						    	   }else{
						    	   	 zhuantai="未评价";
						    	   }
						    }
			var quanbuleirong=
			'<div class="detail_goods clearfix">'+
						'<h4>'+n.shop.storeName+'<span>'+zhuantai+'</span></h4>';
	          $.each(n.goodsCarList, function(k,m) {
	          	 quanbuleirong+='<div class="clearfix tuwen">';
	          	   
	          	       if(n.status==0){
	          quanbuleirong+='<a href="12.8.1buy_dingdan_daifukuan_detail.html?id='+n.id+'">';
	          	       }else if(n.status==1){
	          	   if(n.tradeStatus==0){
	          	   	 quanbuleirong+='<a href="12.8.2buy_dingdan_daifahuo_detail.html?id='+n.id+'">';
	          	   }else{
	          quanbuleirong+='<a href="12.8.2buy_dingdan_daishouhuo_detail.html?id='+n.id+'">';
	          	   }
	          	      }else  if(n.status==3){
				 quanbuleirong+='<a href="12.8.3buy_dingdan_wancheng_detail.html?id='+n.id+'">';
						    	   }else if(n.status==2){
					 quanbuleirong+='<a href="12.8.3buy_dingdan_daipingjia_detail.html?id='+n.id+'">';
						    	   }
						    
    	                quanbuleirong+= '<div class="tuwen-img fl">'+
	          	 '<img  onerror="errorImg2(this)" src="'+m.goods.coverUrl+'" width="75" height="75">'+
	        '</div>'+
	        '<div class="tuwen-wenzi">'+
	            '<h5 class="wuye_h01">'+m.goods.goodsTitle+'</h5>'+
	         /*   '<div class="wuye_div01">'+m.goodsSimple+'</div>'+*/
	        '</div>'+
        '</a>'+
    '</div>';
              if(m.myStockList!=null){
    	  $.each(m.myStockList, function(q,w) {
           	   quanbuleirong+='<div class="dingdan_fenlei clearfix">'+
    	  '<ul class="fl">';
    		if(w.colour!=null){
    quanbuleirong+='<li>颜色：<span>'+w.colour.colourName+'</span></li>';
    		}
    		
    		if(w.size!=null){
    quanbuleirong+='<li>尺码：<span>'+w.size.sizeName+'</span></li>';			
    		}
    		if(m.packRate!=null){
    quanbuleirong+='<li>单价：<span>'+m.packRate+'元/件</span></li>';
    		}
    	
    		
    quanbuleirong+='</ul>'+
    	'<div class="fr">';
    	  /* 
    	      if(n.goodsNumber>=m.tradeNumber){*/
    	      	quanbuleirong+='<h5>'+(m.packRate*w.saleNum)+'元</h5>'+
    		'<h6>'+w.saleNum+'件</h6>';
    	     /* }else{
    	     quanbuleirong+='<h5>'+m.goods.packPrice+'元</h5>'+
    		'<h6>'+n.goodsNumber+'件</h6>';
    	      }*/
    	quanbuleirong+='</div>'+
              '</div>';
           });
          }
             });
           
            	     if(n.status==0){
		 quanbuleirong+='<div class="dingdan_footer">'+
    	     '<div class="fr">'+
    		'<span class="dingdan_quxiao" onclick="bianhaos('+n.orderNumber+')">取消订单</span>'+
    		'<a href="../12.0.0zhifu_goods.html?orid='+n.id+'">去支付</a>'+
    	     '</div>'+
              '</div>'+
               '</div>';
            	    }else if(n.status==1){
						    	if(n.tradeStatus==0){
			quanbuleirong+='<div class="dingdan_footer">'+
		
'    	<div class="fr">'+
'    		<span class="dingdan_tixing" id="oder'+n.id+'" onclick="tixingfahuo(this,'+n.id+')">提醒发货</span>'+
'    	</div>'+
'    	<div class="fr">'+
'    		<a href="12.9.2buy_dingdan_tuikuan_shenqing.html?id='+n.id+'" class="dingdan_footer_hui">申请退款</a>'+
'    	</div>'+	
'    </div>'+
'</div>';
						    	}else if(n.tradeStatus==1){
					 quanbuleirong+='  <div class="dingdan_footer">'+
'    	<div class="fr">'+
'    		<a href="12.9.2buy_dingdan_tuikuan_shenqing.html?uId='+n.userId+'&dId='+n.id+'" class="dingdan_footer_hui">申请退款</a>'+
'    		<a href="javascript:shouhuoqueren('+n.id+');" class="dingdan_queren">确认收货</a>'+
'    	</div>'+
'    </div>'+
'</div>';
						    	
						    }
						}else if(n.status==8){
							
			 quanbuleirong+='<div class="dingdan_footer">'+
    	'<div class="fr">'+
    		'<span class="dingdan_quxiao" onclick="quxiaotuikuan('+n.id+')">取消退款</span>'+
    	'</div>'+
    '</div>'+
'</div>';
						}else if(n.status==9){
							
				quanbuleirong+='<div class="dingdan_footer">'+
				'<div class="fr">'+
    		'<span class="dingdan_shanchu" onclick="bianhaos('+n.orderNumber+')">删除</span>'+
    	'</div>'+
    '</div>'+
'</div>';		    	
						    
						}else if(n.status==10){
				quanbuleirong+='<div class="dingdan_footer">'+
				'<div class="fr">'+
    		'<span class="dingdan_shanchu" onclick="bianhaos('+n.orderNumber+')">删除</span>'+
    	'</div>'+
    '</div>'+
'</div>';		    	
						    }else
						    	   if(n.status==3){
						    	  quanbuleirong+='<div class="dingdan_footer">'+
'    	<div class="fr">'+
'    		<span class="dingdan_shanchu" onclick="bianhaos('+n.orderNumber+')">删除</span>'+
'    	</div>'+
'    </div>'+
'</div>';
						    	   }else if(n.status==2){
						    	   	
						    	 quanbuleirong+=' <div class="dingdan_footer">'+
'    	<div class="fr">'+
'    		<a href="12.8.4buy_dingdan_pingjia.html?id='+n.id+'">去评价</a>'+
'    	</div>'+
'    </div>'+
'</div>';
						    	   }
						    
						$("#quanbuleirong").append(quanbuleirong);
						 }
			});
			
			      $(function(){
			      	 // 取消订单
    // 弹出
    $(".dingdan_quxiao").on('click',function(){
        $("body").append("<div id='mask'></div>");
        $(".show-quxiao").show();
    })
    //点击关闭
    $(".Quxiao").on('click',function(){
        $(".show-quxiao").hide();
        $("#mask").remove();
    }) 
    
    //提醒发货
    $('.dingdan_tixing').on('click',function(){		
		$(this).html("已提醒").css("background","#f5f5f5");
		//alert("123")
	});	
    
    
    //确认收货
    // 弹出
    $(".dingdan_queren").on('click',function(){
        $("body").append("<div id='mask'></div>");
        $(".show-queren").show();
    })
    //点击关闭
    $(".Quxiao").on('click',function(){
        $(".show-queren").hide();
        $("#mask").remove();
    }) 
    
    
    //删除
    // 弹出
    $(".dingdan_shanchu").on('click',function(){
        $("body").append("<div id='mask'></div>");
        $(".show-shanchu").show();
    })
    //点击关闭
    $(".Quxiao").on('click',function(){
        $(".show-shanchu").hide();
        $("#mask").remove();
    }) 
			      });
			
					
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}

				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				alert("error");
			}
		});
		}
	}
	
//取消订单

function bianhaos(te){
	$("#biaohaos").val("");
	$("#biaohaos").val(te);
}

function  querenquxiao(){
	
	 var biaohaos=$("#biaohaos").val();  
	 if(biaohaos==''){
	 	//alert("出现异常");
	 }else{
   	  $.ajax({
      url: urlcore+"/api/order/cancelOrder?orderNumber="+biaohaos,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					//selectGoodsList2();
					  window.location.reload();				 
				  	 
				}
		/*console.log(goodslist);*/
			},
			error: function() {
				alert("error");
			}
		});
}
	 
	 
}


function  querenquxiao22(){
	 var biaohaos=$("#biaohaos").val();  
	 if(biaohaos==''){
	 	//alert("未获取")
	 	//alert("出现异常");
	 }else{
	 	 if(uuuuid!=''){
	 	
   	  $.ajax({
      url: urlcore+"/api/order/delete2?orderNumber="+biaohaos+"&userId="+uuuuid,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					//selectGoodsList2();
                 window.location.reload();				  	 
				}else{
					alert(data.msg);
				}
			},
			error: function() {
				alert("error");
			}
		});
		 	
	 	 }
}
	 
	 
}

function  quxiaotuikuan(te){
   	  $.ajax({
      url: urlcore+"/api/refundOrder/cancelRefundOrder?orderId="+te,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					//selectGoodsList2();
                 window.location.reload();				  	 
				}
			},
			error: function() {
				alert("error");
			}
		});
}
function shouhuoqueren(oid){
	   $("#orid").val("");
	   $("#orid").val(oid);	   
}


function querensh(t){
            var orids=$("#orid").val();
            if(orids!=''&&orids!=null){
   	  $.ajax({
      url: urlcore+"/api/order/updataorders?id="+orids+"&status="+t,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
			/*		var dangqian=window.location.href;
					window.location.href=dangqian;*/
    window.location.reload();
				}else{
					  alert("失败");
				}
		/*console.log(goodslist);*/
			},
			error: function() {
				alert("error");
			}
		});
     
 }
}
